

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  <meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>Operating the Read (Primary) Balancer &mdash; Ceph Documentation</title>
  

  
  <link rel="stylesheet" href="../../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/graphviz.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/css/custom.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script src="../../../_static/jquery.js"></script>
        <script src="../../../_static/_sphinx_javascript_frameworks_compat.js"></script>
        <script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script>
        <script src="../../../_static/doctools.js"></script>
        <script src="../../../_static/sphinx_highlight.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../../genindex/" />
    <link rel="search" title="Search" href="../../../search/" />
    <link rel="next" title="均衡器模块" href="../balancer/" />
    <link rel="prev" title="使用 pg-upmap" href="../upmap/" /> 
</head>

<body class="wy-body-for-nav">

   
  <header class="top-bar">
    <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../../../" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="../../">Ceph 存储集群</a></li>
          <li class="breadcrumb-item"><a href="../">集群运维</a></li>
      <li class="breadcrumb-item active">Operating the Read (Primary) Balancer</li>
      <li class="wy-breadcrumbs-aside">
            <a href="../../../_sources/rados/operations/read-balancer.rst.txt" rel="nofollow"> View page source</a>
      </li>
  </ul>
  <hr/>
</div>
  </header>
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #eee" >
          

          
            <a href="../../../" class="icon icon-home"> Ceph
          

          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../../start/">Ceph 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../install/">安装 Ceph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../cephadm/">Cephadm</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../../">Ceph 存储集群</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../../configuration/">配置</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../">运维</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../operating/">操纵集群</a></li>
<li class="toctree-l3"><a class="reference internal" href="../health-checks/">健康检查</a></li>
<li class="toctree-l3"><a class="reference internal" href="../monitoring/">监控集群</a></li>
<li class="toctree-l3"><a class="reference internal" href="../monitoring-osd-pg/">监控 OSD 和归置组</a></li>
<li class="toctree-l3"><a class="reference internal" href="../user-management/">用户管理</a></li>
<li class="toctree-l3"><a class="reference internal" href="../pgcalc/">PG Calc</a></li>
<li class="toctree-l3"><a class="reference internal" href="../data-placement/">数据归置概览</a></li>
<li class="toctree-l3"><a class="reference internal" href="../pools/">存储池</a></li>
<li class="toctree-l3"><a class="reference internal" href="../erasure-code/">纠删码</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cache-tiering/">分级缓存</a></li>
<li class="toctree-l3"><a class="reference internal" href="../placement-groups/">归置组</a></li>
<li class="toctree-l3"><a class="reference internal" href="../upmap/">使用 pg-upmap</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">Operating the Read (Primary) Balancer</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#online-optimization">Online Optimization</a></li>
<li class="toctree-l4"><a class="reference internal" href="#offline-optimization">Offline Optimization</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../balancer/">均衡器模块</a></li>
<li class="toctree-l3"><a class="reference internal" href="../crush-map/">CRUSH 图</a></li>
<li class="toctree-l3"><a class="reference internal" href="../crush-map-edits/">手动编辑一个 CRUSH 图</a></li>
<li class="toctree-l3"><a class="reference internal" href="../stretch-mode/">Stretch Clusters</a></li>
<li class="toctree-l3"><a class="reference internal" href="../change-mon-elections/">Configuring Monitor Election Strategies</a></li>
<li class="toctree-l3"><a class="reference internal" href="../add-or-rm-osds/">增加/删除 OSD</a></li>
<li class="toctree-l3"><a class="reference internal" href="../add-or-rm-mons/">增加/删除监视器</a></li>
<li class="toctree-l3"><a class="reference internal" href="../devices/">设备管理</a></li>
<li class="toctree-l3"><a class="reference internal" href="../bluestore-migration/">迁移到 BlueStore</a></li>
<li class="toctree-l3"><a class="reference internal" href="../control/">命令参考</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/community/">Ceph 社区</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/troubleshooting-mon/">监视器故障排除</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/troubleshooting-osd/">OSD 故障排除</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/troubleshooting-pg/">归置组排障</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/log-and-debug/">日志记录和调试</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/cpu-profiling/">CPU 剖析</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/memory-profiling/">内存剖析</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../man/">    手册页</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../troubleshooting/">故障排除</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../api/">APIs</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../../cephfs/">Ceph 文件系统</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../rbd/">Ceph 块设备</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../radosgw/">Ceph 对象网关</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mgr/">Ceph 管理器守护进程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mgr/dashboard/">Ceph 仪表盘</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../monitoring/">监控概览</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api/">API 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../architecture/">体系结构</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../dev/developer_guide/">开发者指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../dev/internals/">Ceph 内幕</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../governance/">项目管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../foundation/">Ceph 基金会</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../ceph-volume/">ceph-volume</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../releases/general/">Ceph 版本（总目录）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../releases/">Ceph 版本（索引）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../security/">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../hardware-monitoring/">硬件监控</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../glossary/">Ceph 术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../jaegertracing/">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../translation_cn/">中文版翻译资源</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../">Ceph</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
<div id="dev-warning" class="admonition note">
  <p class="first admonition-title">Notice</p>
  <p class="last">This document is for a development version of Ceph.</p>
</div>
  <div id="docubetter" align="right" style="padding: 5px; font-weight: bold;">
    <a href="https://pad.ceph.com/p/Report_Documentation_Bugs">Report a Documentation Bug</a>
  </div>

  
  <section id="operating-the-read-primary-balancer">
<span id="read-balancer"></span><h1>Operating the Read (Primary) Balancer<a class="headerlink" href="#operating-the-read-primary-balancer" title="Permalink to this heading"></a></h1>
<p>You might be wondering: How can I improve performance in my Ceph cluster?
One important data point you can check is the <code class="docutils literal notranslate"><span class="pre">read_balance_score</span></code> on each
of your replicated pools.</p>
<p>This metric, available via <code class="docutils literal notranslate"><span class="pre">ceph</span> <span class="pre">osd</span> <span class="pre">pool</span> <span class="pre">ls</span> <span class="pre">detail</span></code> (see <a class="reference internal" href="../pools/#rados-pools"><span class="std std-ref">存储池</span></a>
for more details) indicates read performance, or how balanced the primaries are
for each replicated pool. In most cases, if a <code class="docutils literal notranslate"><span class="pre">read_balance_score</span></code> is above 1
(for instance, 1.5), this means that your pool has unbalanced primaries and that
you may want to try improving your read performance with the read balancer.</p>
<section id="online-optimization">
<h2>Online Optimization<a class="headerlink" href="#online-optimization" title="Permalink to this heading"></a></h2>
<section id="enabling">
<h3>Enabling<a class="headerlink" href="#enabling" title="Permalink to this heading"></a></h3>
<p>To enable automatic read balancing, you must turn on the <em>balancer module</em>
(enabled by default in new clusters) and set the mode to <code class="docutils literal notranslate"><span class="pre">read</span></code> or <code class="docutils literal notranslate"><span class="pre">upmap-read</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><style type="text/css">
span.prompt1:before {
  content: "$ ";
}
</style><span class="prompt1">ceph<span class="w"> </span>balancer<span class="w"> </span>on</span>
<span class="prompt1">ceph<span class="w"> </span>balancer<span class="w"> </span>mode<span class="w"> </span>&lt;read<span class="p">|</span>upmap-read&gt;</span>
</pre></div></div><p>Both <code class="docutils literal notranslate"><span class="pre">read</span></code> and <code class="docutils literal notranslate"><span class="pre">upmap-read</span></code> mode make use of <code class="docutils literal notranslate"><span class="pre">pg-upmap-primary</span></code>. In order
to use <code class="docutils literal notranslate"><span class="pre">pg-upmap-primary</span></code>, the cluster cannot have any pre-Reef clients.</p>
<p>If you want to use a different balancer or if you want to make your
own custom <code class="docutils literal notranslate"><span class="pre">pg-upmap-primary</span></code> entries, you might want to turn off the balancer in
order to avoid conflict:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">ceph<span class="w"> </span>balancer<span class="w"> </span>off</span>
</pre></div></div><p>To allow use of the new feature on an existing cluster, you must restrict the
cluster to supporting only Reef (and newer) clients.  To do so, run the
following command:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">ceph<span class="w"> </span>osd<span class="w"> </span>set-require-min-compat-client<span class="w"> </span>reef</span>
</pre></div></div><p>This command will fail if any pre-Reef clients or daemons are connected to
the monitors. To see which client versions are in use, run the following
command:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">ceph<span class="w"> </span>features</span>
</pre></div></div></section>
<section id="balancer-module">
<h3>Balancer Module<a class="headerlink" href="#balancer-module" title="Permalink to this heading"></a></h3>
<p>The <cite>balancer</cite> module for <code class="docutils literal notranslate"><span class="pre">ceph-mgr</span></code> will automatically balance the number of
primary PGs per OSD if set to <code class="docutils literal notranslate"><span class="pre">read</span></code> or <code class="docutils literal notranslate"><span class="pre">upmap-read</span></code> mode. See <a class="reference internal" href="../balancer/#balancer"><span class="std std-ref">均衡器模块</span></a>
for more information.</p>
</section>
</section>
<section id="offline-optimization">
<h2>Offline Optimization<a class="headerlink" href="#offline-optimization" title="Permalink to this heading"></a></h2>
<p>Primaries are updated with an offline optimizer that is built into the
<a class="reference internal" href="../../../man/8/osdmaptool/#osdmaptool"><span class="std std-ref">osdmaptool -- ceph osd 运行图操作工具</span></a>.</p>
<ol class="arabic">
<li><p>Grab the latest copy of your osdmap:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">ceph<span class="w"> </span>osd<span class="w"> </span>getmap<span class="w"> </span>-o<span class="w"> </span>om</span>
</pre></div></div></li>
<li><p>Run the optimizer:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">osdmaptool<span class="w"> </span>om<span class="w"> </span>--read<span class="w"> </span>out.txt<span class="w"> </span>--read-pool<span class="w"> </span>&lt;pool<span class="w"> </span>name&gt;<span class="w"> </span><span class="o">[</span>--vstart<span class="o">]</span></span>
</pre></div></div><p>It is highly recommended that you run the capacity balancer before running the
balancer to ensure optimal results. See <a class="reference internal" href="../upmap/#upmap"><span class="std std-ref">使用 pg-upmap</span></a> for details on how to balance
capacity in a cluster.</p>
</li>
<li><p>Apply the changes:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1"><span class="nb">source</span><span class="w"> </span>out.txt</span>
</pre></div></div><p>In the above example, the proposed changes are written to the output file
<code class="docutils literal notranslate"><span class="pre">out.txt</span></code>. The commands in this procedure are normal Ceph CLI commands
that can be run in order to apply the changes to the cluster.</p>
<p>If you are working in a vstart cluster, you may pass the <code class="docutils literal notranslate"><span class="pre">--vstart</span></code> parameter
as shown above so the CLI commands are formatted with the <cite>./bin/</cite> prefix.</p>
<p>Note that any time the number of pgs changes (for instance, if the pg autoscaler [<a class="reference internal" href="../placement-groups/#pg-autoscaler"><span class="std std-ref">自动伸缩归置组</span></a>]
kicks in), you should consider rechecking the scores and rerunning the balancer if needed.</p>
</li>
</ol>
<p>To see some details about what the tool is doing, you can pass
<code class="docutils literal notranslate"><span class="pre">--debug-osd</span> <span class="pre">10</span></code> to <code class="docutils literal notranslate"><span class="pre">osdmaptool</span></code>. To see even more details, pass
<code class="docutils literal notranslate"><span class="pre">--debug-osd</span> <span class="pre">20</span></code> to <code class="docutils literal notranslate"><span class="pre">osdmaptool</span></code>.</p>
</section>
</section>



<div id="support-the-ceph-foundation" class="admonition note">
  <p class="first admonition-title">Brought to you by the Ceph Foundation</p>
  <p class="last">The Ceph Documentation is a community resource funded and hosted by the non-profit <a href="https://ceph.io/en/foundation/">Ceph Foundation</a>. If you would like to support this and our other efforts, please consider <a href="https://ceph.io/en/foundation/join/">joining now</a>.</p>
</div>


           </div>
           
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="../upmap/" class="btn btn-neutral float-left" title="使用 pg-upmap" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="../balancer/" class="btn btn-neutral float-right" title="均衡器模块" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2016, Ceph authors and contributors. Licensed under Creative Commons Attribution Share Alike 3.0 (CC-BY-SA-3.0).</p>
  </div>

   

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>